package com.tubeonfire.controller.admin;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tubeonfire.model.admin.MissionModel;

@SuppressWarnings("serial")
public class ListMissionServlet extends HttpServlet {

	private static final Logger log = Logger.getLogger(ListMissionServlet.class
			.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		try {
			int page = 1;
			try {
				page = Integer.parseInt((String) req.getParameter("page"));
			} catch (Exception e) {
				page = 1;
			}
			int status = 0;
			int type = 0;
			String strStatus = req.getParameter("status");
			String strType = req.getParameter("type");
			if (strStatus != null) {
				try {
					status = Integer.parseInt(strStatus);
				} catch (Exception e) {

				}
			}
			if (strType != null) {
				try {
					type = Integer.parseInt(strType);
				} catch (Exception e) {

				}
			}
			MissionModel model = new MissionModel();
			model.setPage(page);
			model.search(status, type);
			req.setAttribute("status", status);
			req.setAttribute("type", type);
			req.setAttribute("url", req.getRequestURL().toString());
			req.setAttribute("result", model);
			req.getRequestDispatcher("/admin/list_mission.jsp").forward(req,
					resp);
		} catch (Exception e) {
			log.warning(e.toString());
			e.printStackTrace();
			resp.sendError(4004,
					"We are sorry for the inconvenience ! Please try again later !");
		}
	}
}
